package com.java.simple.smallspring.aop;

import com.java.simple.smallspring.util.ClassUtil;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
 * @author zhoujunlin
 * @date 2022年09月10日 16:20
 * @desc Used to obtain the current "target" of an AOP invocation,
 * which will be invoked via reflection if no around advice choose
 * to end the interceptor chain itself
 * 被代理的目标对象
 */
@Getter
@RequiredArgsConstructor
public class TargetSource {

    private final Object target;

    public Class<?>[] getTargetClass() {
        Class<?> clazz = this.getTarget().getClass();
        clazz = ClassUtil.isCglibProxyClass(clazz) ? clazz.getSuperclass() : clazz;
        return clazz.getInterfaces();
    }

}
